package com.dd.admin.business.sell.enums;


import com.dd.admin.common.exception.ApiException;

import java.util.Arrays;

import static com.dd.admin.business.pay.enmus.CashierExceptionEnum.PAY_SELL_CANCEL_ERROR;
import static com.dd.admin.business.pay.enmus.PayConst.*;


public enum CancelSellServiceEnum {
    CANCEL_MEMBER_BUILD_CARD(SELL_TYPE_BUILD_CARD,"cancelMemberBuildCard"),
    CANCEL_MEMBER_CHARGED_CARD(SELL_TYPE_CHARGED_CARD,"cancelMemberChargedCard"),
    CANCEL_MEMBER_PRODUCT(SELL_TYPE_PRODUCT,"cancelMemberProduct"),
    ;

    private Integer sellType;
    private String serviceName;

    CancelSellServiceEnum(Integer sellType, String serviceName) {
        this.sellType = sellType;
        this.serviceName = serviceName;
    }

    public Integer getSellType() {
        return sellType;
    }

    public void setSellType(Integer sellType) {
        this.sellType = sellType;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public static CancelSellServiceEnum getEnumBySellType(Integer sellType) {
        CancelSellServiceEnum[] cancelSellServiceEnums = CancelSellServiceEnum.values();
        return Arrays.stream(cancelSellServiceEnums)
                .filter(cancelSellServiceEnum -> cancelSellServiceEnum.getSellType().equals(sellType))
                .findFirst().orElseThrow(() -> new ApiException(PAY_SELL_CANCEL_ERROR));
    }
}
